/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOS;

import Modelos.Vehiculo;
import bean.Conexion;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author gerardo
 */
public class DAOVehiculo extends ConexionDAO {
    private List<Vehiculo> vehiculoLista = new ArrayList<Vehiculo>();
    
    public DAOVehiculo()
    {
        super();
    }

    public List<Vehiculo> getVehiculoLista() {
        return vehiculoLista;
    }
    
    public void registrarVehiculo(Vehiculo vehic)
    {
        String tiraSQL ="INSERT INTO vehiculo (placa,cod_socio,cod_tipo,annio,marca,modelo,color)"+
                        "VALUES('"+vehic.getPlaca()+"','"+vehic.getCodSocio()+"','"+vehic.getCod_tipov()+"','"+vehic.getAnno()+"','"+vehic.getMarca()+"','"+vehic.getModelo()+"','"+vehic.getColor()+"')";
        Conexion.ejecutar(tiraSQL);
    }
    
   
    
    public void cargarVehiculos()
    {
        
        vehiculoLista = new ArrayList<Vehiculo>();
        ResultSet resultset = null;
        
        String tiraSQL ="SELECT * FROM vehiculo";
        resultset = Conexion.consultar(tiraSQL);
        
        try {
            while(resultset.next())
            {
                String placa = resultset.getString("placa");
                String cod_socio = resultset.getString("cod_socio");
                Date annio = resultset.getTimestamp("annio");
                String marca = resultset.getString("marca");
                String modelo = resultset.getString("modelo");
                String color = resultset.getString("color");
                String cod_tipo = resultset.getString("cod_tipo");
   
                Vehiculo vehi = new Vehiculo(placa, marca, modelo, annio, color, cod_tipo, cod_socio);
                vehiculoLista.add(vehi);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        
    }
    
    public Vehiculo buscarVehiculo(String valor)
    {
        Vehiculo vehi = new Vehiculo();
        ResultSet resultset = null;
        String tiraSQL = "SELECT * FROM vehiculo,tipovehiculo WHERE vehiculo.placa='"+valor+"'";
        resultset = Conexion.consultar(tiraSQL);
        
        try {
            while(resultset.next()){
                String placa = resultset.getString("placa");
                String cod_socio = resultset.getString("cod_socio");
                Date annio = resultset.getTimestamp("annio");
                String marca = resultset.getString("marca");
                String modelo = resultset.getString("modelo");
                String color = resultset.getString("color");
                String cod_tipo = resultset.getString("cod_tipo");
             
                vehi = new Vehiculo(placa, marca, modelo, annio, color, cod_tipo, cod_socio);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return vehi;
    }
    
    
}
